package com.shan.design.combination.transparent;

import java.util.ArrayList;

/**
 * description
 * 文件夹类：容器构件
 *
 * @author shanzheng <br/>
 * @date 17:56 2018/11/29.<br/>
 * Modified By <br/>
 */
public class Folder extends AbstractFile {
    private ArrayList<AbstractFile> abstractFiles = new ArrayList<>();
    private String name;

    public Folder(String name) {
        this.name = name;
    }

    @Override
    void add(AbstractFile file) {
        abstractFiles.add(file);
    }

    @Override
    void remove(AbstractFile file) {
        abstractFiles.remove(file);
    }

    @Override
    AbstractFile getChild(int i) {
        return abstractFiles.get(i);
    }

    @Override
    void killVirus() {
        //模拟杀毒
        System.out.println("****对文件夹'" + name + "'进行杀毒");
        for (AbstractFile abstractFile : abstractFiles) {
            abstractFile.killVirus();
        }
    }
}
